﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using BCGC.BLL.MailManager;
using Jalal.Library.Web;

public partial class Member_mailOutBox : MemberBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           LoadData();
        }
    }

    public string GetFormattedContent(string content)
    {
        content = Server.HtmlDecode(content);
        if (content.Length > 60)
        {
            return content.Substring(0, 60);
        }
        else
        {
            return content;
        }
    }
    

    private void LoadData()
    {
        int totalRecords = 0;
        grvOutbox.DataSource = PrivateMessage.GetPrivateMessageBySenderID(SessionManager.LoggedUser.Id, "SendDate", "Desc", 1, 10, out totalRecords);
        grvOutbox.DataBind();
    }
    protected void grvOutbox_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            PrivateMessage message = e.Row.DataItem as PrivateMessage;
            if (message != null)
            {
                if (message.IsRead)
                {
                    e.Row.CssClass = "MailRead";
                }
                else
                {
                    e.Row.CssClass = "MailUnread";
                }
            }
        }
    }
    protected void linkDelete_Click(object sender, EventArgs e)
    {
        try
        {
            foreach (GridViewRow grv in grvOutbox.Rows)
            {
                CheckBox chkSelect = grv.FindControl("chkSelect") as CheckBox;
                if (chkSelect != null)
                {
                    if (chkSelect.Checked)
                    {
                        int messageID = Convert.ToInt32(grvOutbox.DataKeys[grv.DataItemIndex]);
                        PrivateMessage message = PrivateMessage.GetPrivateMessageByMessageID(messageID);
                        message.IsShowOutBox = false;
                        message.Save();
                    }
                }
            }

            uccResponse.SetSuccessMessage("Messages Deleted From OutBox");
        }
        catch
        {
            uccResponse.SetFailMessage("Failed to Delete Messages From OutBox");
        }
    }
}
